<?php
/*
* Module Name: Blog News
* Module URI: 
* Description: Blog News Module For Site Editor Application
* Author: 
* Author URI: 
* Version: 1.0.0
*/

class PBBlogNewsShortcode extends PBShortcodeClass{
    /**
     * Register module with siteeditor.
     */
    function __construct() {
        parent::__construct( array(
                "name"        => "sed_blog_news",                               //*require
                "title"       => __("Blog News","site-editor"),                 //*require for toolbar
                "description" => __("Blog News in Front End","site-editor"),
                "icon"        => "sedico-blog-news",                               //*require for icon toolbar
                "module"      =>  "blog-news"         //*require
            ) // Args
        );
	}
	
    function get_atts(){

        $atts = array(
            'title'          => '',
            'style'          => 'featured',
			'count'          => '5',
			'category'       => '',
			'excerpt'        => false,
			'link'           => '#',
			'link_title'     => 'Read More'
        );
        return $atts;
    }

    function add_shortcode( $atts , $content = null ){


    }             

    function styles(){
        return array(
            array('blog-news-style', SED_PB_MODULES_URL.'blog-news/css/style.css' ,'1.0.0') ,
        );
    }     

    function scripts(){

    }	

    function shortcode_settings(){

	    global $wpdb;
		$request = "SELECT $wpdb->terms.term_id, name FROM $wpdb->terms ";
		$request .= " LEFT JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id ";
		$request .= " WHERE $wpdb->term_taxonomy.taxonomy = 'category' ";
		$request .= " ORDER BY term_id asc";
		$categories = $wpdb->get_results($request);
		$cates=array();
		foreach ($categories as $cate) { 
			$cates[$cate->term_id]=$cate->name;
		}
	
        $this->add_panel( 'blog_news_settings_panel_outer' , array(
            'title'                   =>  __('Blog News Settings',"site-editor")  ,
            'capability'              => 'edit_theme_options' ,
            'type'                    => 'inner_box' ,
            'priority'                => 9 ,
            'btn_style'               => 'menu' ,
            'has_border_box'          => false ,
            'icon'                    => 'sedico-setting-item' ,
            'field_spacing'           => 'sm'
        ) );
		
		$this->add_panel( 'blog_news_settings_panel' , array(
            'title'                   =>  __('Blog News Settings',"site-editor")  ,
            'capability'              => 'edit_theme_options' ,
            'type'                    => 'default' ,
            'parent_id'               => "blog_news_settings_panel_outer",
            'priority'                => 9 ,
        ) );

		
		

        $params = array(
		
			'title'=> array(
				"type"          => "text" ,
				"label"         => __("Title", "site-editor"),
				"panel"         => "blog_news_settings_panel",
				'has_border_box'    => false
			),
			
			'style'=> array(
				"type"          => "select" ,
				"label"         => __("Style", "site-editor"),
				"panel"         => "blog_news_settings_panel",
				"default"       => "featured",
				"choices"       =>array(
				    'default'  =>__("default", "site-editor"),
					'featured' =>__("featured", "site-editor"),
				),
				'has_border_box'    => false
			),
			
		   'category'=> array(
				"type"          => "multi-select" ,
				"label"         => __("Category", "site-editor"),
				"panel"         => "blog_news_settings_panel",
				'choices'       => $cates,
				'has_border_box'    => false
			),
			
			'count'=> array(
				"type"          => "number" ,
				"label"         => __("Count", "site-editor"),
				"panel"         => "blog_news_settings_panel",
				'has_border_box'    => false
			),
			
			'excerpt'=> array(
				"type"          => "switch" ,
				"label"         => __("excerpt", "site-editor"),
				"panel"         => "blog_news_settings_panel",
				"default"       => false,
				'has_border_box'    => false
			),
			
			'link_title'=> array(
				"type"            => "text" ,
				"label"           => __("Link Title", "site-editor"),
				"panel"           => "blog_news_settings_panel",
				"default"         => "READ MORE",
				'has_border_box'  => false
			),
			
			'link'=> array(
				"type"                => "link" ,
				"label"               => __("Link", "site-editor"),
				"panel_type"          => "default" ,
				"parent_id"           => "blog_news_settings_panel",
				"default"             => "#",
				'has_border_box'      => false
			),
			
            'row_container'         => array(
                'type'                  => 'row_container',
                'label'                 => __('Module Wrapper Settings', 'site-editor')
            ), 

            "animation"             =>  array(
                "type"                  => "animation" ,
                "label"                 => __("Animation Settings", "site-editor"),
                'button_style'          => 'menu' ,
                'has_border_box'        => false ,
                'icon'                  => 'sedico-animation' ,
                'field_spacing'         => 'sm' ,
                'priority'              => 530 ,
            )

        );

        return $params;

    }

}

new PBBlogNewsShortcode;

global $sed_pb_app;

$sed_pb_app->register_module(array(
    "group"       => "theme" ,
    "name"        => "blog-news",
    "title"       => __("Blog News","site-editor"),
    "description" => __("Blog News","site-editor"),
    "icon"        => "sedico-blog-news",
    "shortcode"   => "sed_blog_news",
    "transport"     => "ajax"
));

